layui.use(['jquery','layer','table','form','laydate'],function () {
    var $ = layui.jquery,
        layer = layui.layer,
        table = layui.table,
        form = layui.form,
        laydate = layui.laydate;


    //刷新页面
    $("#refresh").click(function () {
        location.reload();
    });
    //返回
    $('#goBack').click(function () {
        parent.tabParentChange(3);
    })
    $(document).click(function () {
        parent.$('.rightMenu').hide();
    });

    //table表格数据
    getTable();
    function getTable() {
        $.ajax({
            url:"/microcircle/getMicrocirclLog",
            data:{"logType": 3},
            type:"post",
            dataType:"json",
            success:function (data) {
                demoTable(data.data);
            }
        })
    }

    function  demoTable(data){
        table.render({
            elem:'#demoTable',
            title:"操作日志",
            data:data,
            toolbar:'#button_ids',
            limit:10,
            page:{
                layout:['count','prev','page','next','limit','skip','refresh'],
                limits:[10,20,30],
                first:"首页",
                last:"尾页",
            },
            cols:[[
                {type:'checkbox'},
                {field:"",title:"序号",align:'center',templet:function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:"trueName",title:"操作人名称",align:'center'},
                {field:"createDate",title:"操作时间",align:'center'},
                {field:"type",title:"操作类型",align:'center',templet:function (data) {
                        if (data.type == 2) {
                            return "添加";
                        }else if(data.type == 3){
                            return "删除";
                        }else if(data.type == 4){
                            return "修改";
                        }else if(data.type == 5){
                            return "查看";
                        }else{
                            return "操作类型不明"
                        }
                    }},
                {field:"remark",title:"操作日志类型",align:'center'},
                {field:'',title:"操作",align:'center',toolbar:"#btnOperation"}
            ]]
        });
    }

    //模糊查询
    search = function search(){
        var trueName = $("#trueName").val();
        var remark = $("#remark").val();
        var typeText = $("#type option:selected").text();//监听下拉框
        var type;
        if(typeText=="查看"){
            type = 5 ;
        }else if(typeText=="删除"){
            type = 3
        }
        var createDate = $("#createDate").val();
        var logType = 3;
        getTableSearch(trueName,remark,type,createDate,logType);
    }


    function getTableSearch(trueName,remark,type,createDate,logType){
        $.ajax({
            url:"/microcircle/getMicrocirclLogSearch",
            type:"post",
            dataType:"json",
            data:{'trueName':trueName,'remark': remark,'type':type,"createDate":createDate,"logType": logType},
            success:function (data) {
                demoTable(data.data);
            }
        })
    };

    //删除操作日志
    table.on("tool(demoTable)",function (obj) {
        if(obj.event == "delTable"){
            layer.confirm('确定删除当前文章吗?', {icon: 3, title:'删除'}, function(index){
                $.ajax({
                    url:'/microcircle/delMicrocirclLog',
                    data:{'logId': obj.data.logId},
                    type:"post",
                    dataType:"json",
                    success : function (data) {
                        if(data.data){
                            layer.msg("删除成功");
                            getTable();
                        }
                    }
                })
            })
        }
    });

})
